/**
 * Created by wanglei@enersun.com.cn on 2016/6/28.
 */
var newsTemplate = "";
var cnewsId;
function doLoadNewsInfo(newsId) {
	cnewsId=newsId;
	$.post(realPath+"/path/newsinfo/viewnewsjson", {"newId":newsId},
			function(result) {
				if (result.state == 'Success') {
					createNewsInfoByTemplate(result.content);
				} else {
					alert("操作失败,原因："+result.content);
				}
			}
		);
}
function doarticle(){
	 //滚动图片信息自适应
		$(".news-imgList-article").each(function(i){
			var $dh = $(".news-imgList-article").eq(i).siblings(".news-imgList-header").height();
			var $oh = $(".news-imgList-article").eq(i).find("p").height();
			var $ph = $(".news-imgList-article").eq(i).parents(".news-imgList-info").height();
			if( $oh < ($ph-$dh) ){
				$(this).find(".j-news-btn").addClass("fn-dn");
				$(this).find(".news-article-content").css({"width":"100%"});
			}
		});
	}
	/*添加背景色*/
	$(".news-imgList-content").parents("html,body").css({"background-color":"rgba(0, 0, 0, 0.95)"});
/**
* 根据模板创建新闻信息
*/
function createNewsInfoByTemplate(newsInfo){
	if(newsInfo.newsdetails.length>0){
		for(var index=0;index<newsInfo.newsdetails.length;index++){
			var newsDetailInfo=newsInfo.newsdetails[index];
			var currNews=$('#newsTemplate').html();
			currNews=currNews.replaceAll("%news.pic%",newsDetailInfo.path);
			currNews=currNews.replaceAll("%currNum%",index+1);
			currNews=currNews.replaceAll("%totalCount%",newsInfo.newsdetails.length);
			currNews=currNews.replaceAll("%news.editor%",newsInfo.editor);
			currNews=currNews.replaceAll("%news.photographer%",newsInfo.photographer);
			currNews=currNews.replaceAll("%news.publishTime%",newsInfo.publishTime);
			currNews=currNews.replaceAll("%news.browseCount%",100);
			if(newsDetailInfo.remark!=undefined){
				currNews=currNews.replaceAll("%news.content%",newsDetailInfo.remark);
			}else{
				currNews=currNews.replaceAll("%news.content%","");
			}
			$('#recommendNews').before(currNews);
		}
		$('#recommendNews').show();
		doarticle();
		swiperC = new Swiper('.swiper-container');
	}
}
/**
* 转到上一页
*/
function swiperGotoPrev(){
	if(swiperC===undefined){
		return;
	}
	swiperC.slidePrev();
}
String.prototype.replaceAll = function(s1,s2) { 
    return this.replace(new RegExp(s1,"gm"),s2); 
}
/**
* 分享功能
*/
function ShareTip(url,newsData)  
{  
    this.shareUrl=url;
	this.shareData=newsData;
}  
//分享到腾讯微博  
ShareTip.prototype.sharetoqq=function()  
{  
	return 'http://v.t.qq.com/share/share.php?title='+this.shareData.title+'&url='+this.shareUrl+'&pic='+this.shareData.coverPath; 
}  
//分享到新浪微博  
ShareTip.prototype.sharetosina=function()  
{  
	return 'http://v.t.sina.com.cn/share/share.php?title='+this.shareData.title+'&url='+this.shareUrl+'&content=utf-8&sourceUrl='+this.shareUrl+'&pic='+this.shareData.coverPath;
}  
//分享到QQ空间  
ShareTip.prototype.sharetoqqzone=function()  
{  
	return 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?summary='+this.shareData.title+'&url='+this.shareUrl+'&pics='+this.shareData.coverPath;  
}

//分享到QQ好友  
ShareTip.prototype.sharetoqqfriend=function()  
{
	var p = {
	url:location.href, /*获取URL，可加上来自分享到QQ标识，方便统计*/
	desc:'', /*分享理由(风格应模拟用户对话),支持多分享语随机展现（使用|分隔）*/
	title:this.shareData.title, /*分享标题(可选)*/
	summary:this.shareData.title, /*分享摘要(可选)*/
	pics:this.shareData.coverPath, /*分享图片(可选)*/
	flash: '', /*视频地址(可选)*/
	site:'图讯', /*分享来源(可选) 如：QQ分享*/
	style:'201',
	width:32,
	height:32
	};
	var s = [];
	var qqurl='http://connect.qq.com/widget/shareqq/index.html?';
	var qqparamindex=0;
	for(var i in p){
		var temp='';
		if(qqparamindex>0){
			temp='&';
		}
		temp+=i + '=' + encodeURIComponent(p[i]||'');
		qqparamindex++;
		qqurl+=temp;
	}
	return qqurl;
}

/**
* 分享到QQ空间
*/
function ShareQQZone(){
	return share1.sharetoqqzone();
}
/**
* 分享到新浪微博  
*/
function ShareSina(){
	return share1.sharetosina();
}
/**
* 分享到腾讯微博  
*/
function ShareQQMicroBlog(){
	return share1.sharetoqq();
}
//分享到QQ好友  
function ShareQQFriend(){
	return share1.sharetoqqfriend(); 
}